// 导入axios实例中的AxiosResponse泛型接口
import type { AxiosResponse } from "axios";
//导入封装的axios请求方法
import request from "../requestMethod";
import type {LoginReq} from "@/interfaces/user";
import type {
    CancelBookReqVO,
    CreateRecordReqVO,
    PageRecordReqVO,
    SeatStatusReqVO,
    UserBookStatusReqVO
} from "@/interfaces/book";
// 参数类型导入


//  如果是get请求不需要写method，post请求使用data请求体 默认封装的get
// post示例
//  export const login = (data) => request({ method: "post", url: '/login', data: data });

// get示例
//  export const getUserList = (params) => request({ url: '/users', params });

// put示例
//     export const getEdit = (data) => request({
//      method: "put",
//      data,
//      url: "users/" + data.uid + "/state/" + data.type,
//    })




/**
 * 登录接口
 * @param data
 */
export const useLoginApi = (data:LoginReq):Promise<AxiosResponse<any, any>> =>
    request({
        method:"POST",
        url:"/admin/user/login",
        data,
    })

export const useGetAreaListApi = ():Promise<AxiosResponse<any, any>> =>
    request({
        method:"POST",
        url:"/admin/area/list"
    })

export const useGetTimeListApi = ():Promise<AxiosResponse<any, any>> =>
    request({
        method:"POST",
        url:"/admin/time/list"
    })

export const useCreateRecordApi = (data:CreateRecordReqVO):Promise<AxiosResponse<any, any>> =>
    request({
        method:"POST",
        url:"/admin/record/create",
        data
    })

export const usePageRecordApi = (data:PageRecordReqVO):Promise<AxiosResponse<any, any>> =>
    request({
        method:"POST",
        url:"/admin/record",
        data
    })

export const useSeatStatusApi = (data:SeatStatusReqVO):Promise<AxiosResponse<any, any>> =>
    request({
        method:"POST",
        url:"/admin/record/status",
        data
    })

export const useUserBookStatusApi = (data:UserBookStatusReqVO):Promise<AxiosResponse<any, any>> =>
    request({
        method:"POST",
        url:"/admin/record/bookStatus",
        data
    })

export const useCancelBookApi = (data:CancelBookReqVO):Promise<AxiosResponse<any, any>> =>
    request({
        method:"POST",
        url:"/admin/record/update",
        data
    })


// 如何在组件使用
/*
// post请求
import { login } from "@/api/api";
const { data: res } = await login(loginForm);
if (res.meta.status !== 200) return ELMessage.error("登录失败！");
ELMessage.success("登录成功！");
// 保存token
localStorage.setItem("token", res.data.token);
// 跳转到首页
router.push("/");
// 获取用户信息
getUserInfoList();
// get请求
import { getUserList } from "@/api/api";
const { data: res } = await getUserList({ pageNum: 1, pagesize: 2 });
if (res.meta.status !== 200) return ELMessage.error("获取分类列表失败！");
editCateForm = res.data;
editCateDialogVisible.value = true;
// put请求
import { getEdit } from "@/api/api";
const { data: res } = await getEdit({
  uid: row.uid,
  type: row.mg_state,
});
if (res.meta.status !== 200) return ELMessage.error("修改状态失败！");
ELMessage.success("修改状态成功！");
getUserList();
*/